package dobest.ray.com.jiongjiong.activity.HomePage.statue;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.dobest.ray.corelibs.utils.Tools;

import java.util.ArrayList;
import java.util.List;

import dobest.ray.com.jiongjiong.R;
import dobest.ray.com.jiongjiong.activity.BaseActivity;
import dobest.ray.com.jiongjiong.activity.HomePage.HomePagePresenter;
import dobest.ray.com.jiongjiong.bean.NewVisionBean;
import dobest.ray.com.jiongjiong.bean.NewVisionListBean;
import dobest.ray.com.jiongjiong.bean.PresenterData;
import dobest.ray.com.jiongjiong.bean.VisionData;
import dobest.ray.com.jiongjiong.callback.PresenterCallBack;
import dobest.ray.com.jiongjiong.views.CornerTextView;
import dobest.ray.com.jiongjiong.views.NavigationBar;
import dobest.ray.com.jiongjiong.views.chart.HoriScrollView;

/**
 * 远视力
 */
public class FarVisonActivity extends BaseActivity<HomePagePresenter> implements OnClickListener, PresenterCallBack {

    private HoriScrollView hori_can_scroll_view;
    private List<VisionData> visionDataList = new ArrayList<VisionData>();

    private NewVisionBean bean;
    private TextView tv_re_left;
    private CornerTextView tv_left_eye_notice;
    private TextView tv_re_du_right;
    private CornerTextView tv_right_eye_notice;
    private TextView tv_advice;
    private TextView tv_re_du_s;
    private CornerTextView tv_left_eye_notice_s;
    private TextView tv_re_du_right_s;
    private CornerTextView tv_right_eye_notice_s;
    private TextView tv_re_du_s1;
    private TextView tv_re_du_right_s1;
    private TextView tv_left_eye_notice_s1;
    private TextView tv_right_eye_notice_s1;
    private TextView tv_rate_notice;
    private TextView tv_rate_du;
    private TextView tv_rate_notice_r;
    private TextView tv_rate_notice_r_du;


    private Handler handler = new Handler() {

        public void handleMessage(Message msg) {

            switch (msg.what) {
                case 1:
                    if (visionDataList != null) {

                        setData();
                    }
                    break;
                default:
                    break;
            }
        }

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_vision);
        findViews();
        init();
        addListeners();
    }

    @Override
    public void findViews() {
        navi = (NavigationBar) findViewById(R.id.navi);
        navi.setTitle("视力");
        navi.setBackListener(R.mipmap.img_back, "");
        hori_can_scroll_view = (HoriScrollView) findViewById(R.id.hori_can_scroll_view);
        tv_re_left = (TextView) findViewById(R.id.tv_re_left);
        tv_left_eye_notice = (CornerTextView) findViewById(R.id.tv_left_eye_notice);
        tv_re_du_right = (TextView) findViewById(R.id.tv_re_du_right);
        tv_right_eye_notice = (CornerTextView) findViewById(R.id.tv_right_eye_notice);
        tv_advice = (TextView) findViewById(R.id.tv_advice);
        tv_re_du_s = (TextView) findViewById(R.id.tv_re_du_s);
        tv_left_eye_notice_s = (CornerTextView) findViewById(R.id.tv_left_eye_notice_s);
        tv_re_du_right_s = (TextView) findViewById(R.id.tv_re_du_right_s);
        tv_right_eye_notice_s = (CornerTextView) findViewById(R.id.tv_right_eye_notice_s);
        tv_re_du_s1 = (TextView) findViewById(R.id.tv_re_du_s1);
        tv_re_du_right_s1 = (TextView) findViewById(R.id.tv_re_du_right_s1);
        tv_left_eye_notice_s1 = (TextView) findViewById(R.id.tv_left_eye_notice_s1);
        tv_right_eye_notice_s1 = (TextView) findViewById(R.id.tv_right_eye_notice_s1);
        tv_rate_notice = (TextView) findViewById(R.id.tv_rate_notice);
        tv_rate_du = (TextView) findViewById(R.id.tv_rate_du);
        tv_rate_notice_r = (TextView) findViewById(R.id.tv_rate_notice_r);
        tv_rate_notice_r_du = (TextView) findViewById(R.id.tv_rate_notice_r_du);

        setPresenter(new HomePagePresenter(), this);
    }

    @Override
    public void init() {
        hori_can_scroll_view.setTitle("视力历史变化情况");

        //获取远视力数据
        getPresenter().getFarVisionData(this, "160");
    }

    @Override
    public void addListeners() {

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            default:
                break;
        }
    }


    private void setData() {

        tv_re_left.setTextColor(Color.parseColor(bean.colorL5));
        tv_left_eye_notice.setTextColor(Color.parseColor(bean.colorL5));
        tv_re_du_right.setTextColor(Color.parseColor(bean.colorR5));
        tv_right_eye_notice.setTextColor(Color.parseColor(bean.colorR5));

        tv_re_du_s.setTextColor(Color.parseColor(bean.colorL33));
        tv_left_eye_notice_s.setTextColor(Color.parseColor(bean.colorL33));
        tv_re_du_right_s.setTextColor(Color.parseColor(bean.colorR33));
        tv_right_eye_notice_s.setTextColor(Color.parseColor(bean.colorR33));

        tv_re_du_s1.setTextColor(Color.parseColor(bean.colorCorrectedL));
        tv_re_du_right_s1.setTextColor(Color.parseColor(bean.colorCorrectedR));

        tv_left_eye_notice.setText(bean.assessmentL5);
        tv_left_eye_notice_s.setText(bean.assessmentL33);
        tv_right_eye_notice.setText(bean.assessmentR5);
        tv_right_eye_notice_s.setText(bean.assessmentR33);
        tv_advice.setText(bean.msg);
        tv_advice.setTextColor(Color.parseColor(bean.colorMsg));
        tv_rate_notice.setText(bean.assTrendVL);
        tv_rate_du.setText(bean.TrendVL);
        tv_rate_notice_r.setText(bean.assTrendVR);
        tv_rate_notice_r_du.setText(bean.TrendVR);

        if (Tools.isNull(bean.visionL5)) {
            tv_re_left.setText("-");
        } else {
            tv_re_left.setText(bean.visionL5);
        }
        if (Tools.isNull(bean.visionL33)) {
            tv_re_du_s.setText("-");
        } else {
            tv_re_du_s.setText(bean.visionL33);
        }
        if (Tools.isNull(bean.visionR5)) {
            tv_re_du_right.setText("-");
        } else {
            tv_re_du_right.setText(bean.visionR5);
        }
        if (Tools.isNull(bean.visionR33)) {
            tv_re_du_right_s.setText("-");
        } else {
            tv_re_du_right_s.setText(bean.visionR33);
        }
        if (Tools.isNull(bean.correctedVisionL)) {
            tv_re_du_s1.setText("-");
        } else {
            tv_re_du_s1.setText(bean.correctedVisionL);
        }
        if (Tools.isNull(bean.correctedVisionR)) {
            tv_re_du_right_s1.setText("-");
        } else {
            tv_re_du_right_s1.setText(bean.correctedVisionR);
        }
        if (Tools.isNull(bean.assessmentCorrectedL)) {
            tv_left_eye_notice_s1.setVisibility(View.INVISIBLE);
        } else {
            tv_left_eye_notice_s1.setText(bean.assessmentCorrectedL);
        }
        if (Tools.isNull(bean.assessmentCorrectedR)) {
            tv_right_eye_notice_s1.setVisibility(View.INVISIBLE);
        } else {
            tv_right_eye_notice_s1.setText(bean.assessmentCorrectedR);
        }

        List<Float> leftData = new ArrayList<Float>();
        List<Float> rightData = new ArrayList<Float>();
        List<Float> dangerData = new ArrayList<Float>();
        List<String> dateArray = new ArrayList<String>();
        for (NewVisionListBean vData : bean.chart) {

            if (Tools.isNull(vData.visionL5)) {
                leftData.add(0f);
            } else {
                leftData.add(Float.parseFloat(vData.visionL5));
            }
            if (Tools.isNull(vData.visionR5)) {
                rightData.add(0f);
            } else {
                rightData.add(Float.parseFloat(vData.visionR5));
            }
            if (Tools.isNull(vData.standard)) {
                dangerData.add(0f);
            } else {
                dangerData.add(Float.parseFloat(vData.standard));
            }

            // leftData.add(Float.parseFloat(vData.visionL5));
            // rightData.add(Float.parseFloat(vData.visionR5));
            // dangerData.add(Float.parseFloat(vData.standard));
            dateArray.add(vData.handleDate.split(" ")[0]);
        }
        hori_can_scroll_view.setFloat(1);
        hori_can_scroll_view.setSpecial(2.0f, 0f);
        hori_can_scroll_view.setScaleTagVisiable(false);

        hori_can_scroll_view
                .setData(leftData, rightData, dangerData, dateArray);
    }

    @Override
    public <T> void callBackPresenter(PresenterData<T> data) {

    }
}
